﻿using System;
using System.Collections.Generic;
using System.Text;
using jade.core;

namespace MarketSimulator.Utils.Maps
{
    public class Route : IComparable<Route>
    {
        #region Members
        
        /// <summary>
        /// First City
        /// </summary>
        public City CityA { get; set; }

        /// <summary>
        /// Second City
        /// </summary>
        public City CityB { get; set; }

        /// <summary>
        /// Distance between cities
        /// </summary>
        public double Distance { get; set; }

        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="A">City A</param>
        /// <param name="B">City B</param>
        /// <param name="distance">Distance between cities</param>
        public Route(City A, City B, double distance)
        {
            CityA = A;
            CityB = B;
            Distance = distance;
        }

        /// <summary>
        /// Does route contain City?
        /// </summary>
        /// <param name="cityId">City Id</param>
        public bool ContainsCity(long cityId)
        {
            if(CityA.Id == cityId || CityB.Id == cityId)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// Does route contain City?
        /// </summary>
        /// <param name="cityName">City Name</param>
        /// <returns></returns>
        public bool ContainsCity(string cityName)
        {
            if (CityA.Name.Equals(cityName) || CityB.Name.Equals(cityName))
            {
                return true;
            }
            return false;
        }

        #region IComparable
 
        public int CompareTo(Route other)
        {
            if (other.CityA.Equals(CityA) && other.CityB.Equals(CityB))
            {
                if (other.Distance == Distance)
                {
                    return 0;
                }
                else if (other.Distance > Distance)
                {
                    return -1;
                }
                else
                {
                    return 1;
                }
            }
            else if (other.CityA.Equals(CityA))
            {
                return CityB.Name.CompareTo(other.CityB.Name);
            }
            else
            {
                return CityA.Name.CompareTo(other.CityA.Name);
            }
        }

        #endregion
    }
}
